from appium.webdriver.common.mobileby import MobileBy

from AppWorkWxin.PO.addmember import AddMember
from AppWorkWxin.PO.basepage import BasePage


class AddMemberPage(BasePage):
    
    def get_msgtext(self):
        """
        获取该页面特征信息，作为断言判断
        :return: 特征信息（text)
        """
        ele_msg = self.driver.find_element_by_android_uiautomator(
            'new UiSelector().text("手动输入添加")')
        print(ele_msg.text)
        return  ele_msg.text
    
    def get_addways(self, way):
        """
        获取添加成员的方式，进入对应的添加页面
        :return: 对应添加功能页面
        """
        way_set = {
           "手动输入添加" : 1,
            "从微信/手机通讯录中添加" : 2,
            "微信邀请同事" : 3,
            "拍照添加" : 4
        }
        if way_set[way] == 1:
            self.driver.find_element_by_android_uiautomator(
                f'new UiSelector().text("{way}")').click()
            self.desired_capabilities["appActivity"] = ".contact.controller.ContactAddFastModeActivity"
            print(self.desired_capabilities["appActivity"])
            return AddMember()
        
        elif way_set[way] == 2:
            self.driver.find_element_by_android_uiautomator(
                f'new UiSelector().text("{way}")').click()
            # self.desired_capabilities["appActivity"] = ".friends.controller.WechatAndMobileFriendListActivity"
            return AddMember()
        
        elif way_set[way] == 3:
            self.driver.find_element_by_android_uiautomator(
                f'new UiSelector().text("{way}")').click()
            # self.desired_capabilities["appActivity"] = ".friends.controller.MemberInviteMenuActivity"
            return AddMember()
        
        elif way_set[way] == 4:
            self.driver.find_element_by_android_uiautomator(
                f'new UiSelector().text("{way}")').click()
            # self.desired_capabilities["appActivity"] = ".msg.controller.CameraFastImportTakePhotoActivity"
            return AddMember()
        
        else:
            print("不存在的添加方式")
            return
        
        
    def get_tips(self):
        """
        添加成员成功后返回添加成员主页，并提示toast信息：添加成功
        :return: toast提示信息
        """
        tips_ele = self.find(MobileBy.XPATH, "//*[@class='android.widget.Toast' and @text='添加成功']")
        return tips_ele.text
        
        
        
    
    
    
    